<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type='checkbox' v-model='checked' v-on:click='checkedAll'>全选
        <div v-for='checkb in checkboxData' :key="checkb.id">
            <input type='checkbox' v-model='checkboxList' :value="checkb.id">{{checkb.value}}
        </div>
    </div>

    <script src="js/vue.js"></script>
    <script>
        let app = new Vue({
            el: '#app',
            data: {
                checkboxData: [
                    { id: 1, value: '篮球',"type":false},
                    { id: 2, value: '足球',"type":false},
                    { id: 3, value: '乒乓球',"type":false},
                    { id: 4, value: '棒球',"type":false},
                    { id: 5, value: '网球',"type":false}
                ],
                checkboxList: [],
                checked: false
                
            },
            methods: {
                checkedAll: function () {
                    if (this.checked) {//实现反选
                        this.checkboxList = [];
                    } else { //实现全选
                        this.checkboxList = [];
                        this.checkboxData.forEach((item) => {
                            this.checkboxList.push(item.id);
                        });
                    }
                }
            },
            watch:{
                    checkboxData:{
                        handler(val){
                            let count = 0;
                            if(val.type){
                                count++;
                            }
                            console.log(count);
                            if(count == val.length){
                                this.checked = true;
                            }
                        },
                        deep:true
                    }
                }
        });
    </script>
</body>

</html>